package com.ejoysoft.wlanyz.business;

import com.ejoysoft.auth.MD5;
import com.ejoysoft.common.*;
import com.ejoysoft.common.exception.UserUnitIdException;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import java.util.Vector;
import java.util.HashMap;
import java.util.Date;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;


public class Index {
    private Globa globa;
    private DbConnect db;

    //���췽��
    public Index() {
    }

    public Index(Globa globa) {
        this.globa = globa;
        db = globa.db;
    }

    //���췽��
    public Index(Globa globa, boolean b) {
        this.globa = globa;
        db = globa.db;
        if (b) globa.setDynamicProperty(this);
    }

    String strTableName = "wlan_task_conf";
   
    
    //增加用户
    public boolean add(String strTaskType ,String strTestProject,String strTestIndicator, int strIndicatorValue, int strLessorGreat ) {
        String strSql = "";
        strId = UID.getID();
        try {
        	//把用户信息写入数据库
            strSql = "INSERT INTO " + strTableName + "  (strId,strTaskType , strTestProject,strTestIndicator,strIndicatorValue,strLessorGreat,strCreator, dtCreatDate) VALUES (?,?,?,?,?,?,?,to_date(?,'yyyy-MM-dd hh24:mi:ss'))";
            db.prepareStatement(strSql);
            db.setString(1, strId);
            db.setString(2, strTaskType);
            db.setString(3, strTestProject);
            db.setString(4, strTestIndicator);
            db.setInt(5, strIndicatorValue);
            db.setInt(6, strLessorGreat);
            db.setString(7, globa.loginName);
            db.setString(8, Format.getDateTime());
   
            if (db.executeUpdate() > 0) {
                Globa.logger0("增加测试指标", globa.loginName, globa.loginIp, strSql, "任务管理", globa.userSession.getStrDepart());
                return true;
            } else
                return false;
        } catch (Exception e) {
            System.out.println("增加测试指标信息时出错！！");
            e.printStackTrace();
            return false;
        }
    }

   

    public boolean delete(String where) {
        try {
            String sql = "DELETE FROM " + strTableName + "  ".concat(where);
            db.executeUpdate(sql);
            return true;
        } catch (Exception ee) {
            ee.printStackTrace();
            return false;
        }
    }
    
 
    public boolean update(String strId,String strTaskType , String strTestProject , String strTestIndicator, int strIndicatorValue,int strLessorGreat) {
    	
        try {
        	String strSql = "UPDATE  " + strTableName + "  SET  strTaskType = ?, strTestProject = ?, strTestIndicator =? ,strIndicatorValue=?,  strLessorGreat=? ,strCreator = ?, dtCreatDate = to_date(?,'yyyy-MM-dd hh24:mi:ss')  WHERE strId=? ";
        	
        	
            db.prepareStatement(strSql);
            db.setString(1, strTaskType);
            db.setString(2, strTestProject);
            db.setString(3, strTestIndicator);
            db.setInt(4, strIndicatorValue);
            db.setInt(5, strLessorGreat);
            db.setString(6, globa.loginName);
            db.setString(7, Format.getDateTime());
            db.setString(8, strId);
            db.executeUpdate();
            Globa.logger0("修改测试指标信息", globa.loginName, globa.loginIp, strSql, "任务管理", globa.userSession.getStrDepart());
            return true;
        } catch (Exception e) {
            System.out.println("修改测试指标信息时出错：" + e);
            return false;
        }
    }

  //详细显示单条记录
    public Index show(String where) {
        try {
            String strSql = "select * from  " + strTableName + "  ".concat(where);
            ResultSet rs = db.executeQuery(strSql);
            if (rs != null && rs.next())
                return load(rs, true);
            else
                return null;
        } catch (Exception ee) {
            return null;
        }
    }

  //记录集转化为对象
   
  //查询符合条件的记录总数
    public int getCount(String where) {
        int count = 0;
        try {
            String sql = "SELECT count(strId) FROM " + strTableName + "  ";
            if (where.length() > 0) {
                where = where.toLowerCase();
                if (where.indexOf("order") > 0)
                    where = where.substring(0, where.lastIndexOf("order"));
                sql = String.valueOf(sql) + String.valueOf(where);
            }
            ResultSet rs = db.executeQuery(sql);
            if (rs.next())
                count = rs.getInt(1);
            rs.close();
            return count;
        } catch (Exception ee) {
            ee.printStackTrace();
            return count;
        }
    }

  //列表记录集
	public Vector<Index> list(String where, int startRow, int rowCount) {
		Vector<Index> beans = new Vector<Index>();
        try {
            String sql = "SELECT *  FROM  " + strTableName + " ";
            if (where.length() > 0)
                sql = String.valueOf(sql) + String.valueOf(where);
            Statement s = db.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            if (startRow != 0 && rowCount != 0)
                s.setMaxRows((startRow + rowCount) - 1);
            ResultSet rs = s.executeQuery(sql);
            if (rs != null && rs.next()) {
                if (startRow != 0 && rowCount != 0)
                    rs.absolute(startRow);
                do {
                	Index theBean = new Index();
                    theBean = load(rs, false);
                    beans.addElement(theBean);
                } while (rs.next());
            }
            rs.close();
            s.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        }
        return beans;
    }

	 public Index load(ResultSet rs, boolean isView) {
		 Index theBean = new Index();
	        try {
	            theBean.setStrId(rs.getString("strId"));
	            theBean.setStrTaskType(rs.getString("strTaskType"));
	            theBean.setStrTestProject(rs.getString("strTestProject"));
	            theBean.setStrTestIndicator(rs.getString("strTestIndicator"));
	            theBean.setStrIndicatorValue(rs.getInt("strIndicatorValue"));
	            theBean.setStrLessorGreat(rs.getInt("strLessorGreat"));
	            theBean.setStrCreator(rs.getString("strCreator"));
	            theBean.setDtCreatDate(rs.getString("dtCreatDate"));
	          
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return theBean;
	    }
	 public int strtonum(String strLessorGreat) {
		  if(strLessorGreat=="小于")
			  return 1;
          else if(strLessorGreat=="小于等于") 
        	  return 2;
          else if(strLessorGreat=="等于") 
        	  return 3;
          else if(strLessorGreat=="大于") 
        	  return 4;
          else 
        	  return 5;
		}
	 public String numtostring(int great) {
		  if(great==1)
			  return "小于";
         else if(great==2) 
       	  return "小于等于";
         else if(great==3) 
       	  return "等于";
         else if(great==4) 
       	  return "大于";
         else 
       	  return "大于等于";
		}




    private String strId;
    private String strTaskType;
    private String strTestProject;
    private String strTestIndicator;
    private int strIndicatorValue;
    private int strLessorGreat;
    private String strCreator;
    private String dtCreatDate;
    
    public int getStrIndicatorValue() {
		return strIndicatorValue;
	}

	public void setStrIndicatorValue(int strIndicatorValue) {
		this.strIndicatorValue = strIndicatorValue;
	}


	public String getStrId() {
		return strId;
	}

	public void setStrId(String strId) {
		this.strId = strId;
	}

	public String getStrTaskType() {
		return strTaskType;
	}

	public void setStrTaskType(String strTaskType) {
		this.strTaskType = strTaskType;
	}

	public String getStrTestProject() {
		return strTestProject;
	}

	public void setStrTestProject(String strTestProject) {
		this.strTestProject = strTestProject;
	}

	public String getStrTestIndicator() {
		return strTestIndicator;
	}

	public void setStrTestIndicator(String strTestIndicator) {
		this.strTestIndicator = strTestIndicator;
	}

	

	

	public int getStrLessorGreat() {
		return strLessorGreat;
	}

	public void setStrLessorGreat(int strLessorGreat) {
		this.strLessorGreat = strLessorGreat;
	}

	public String getStrCreator() {
		return strCreator;
	}

	public void setStrCreator(String strCreator) {
		this.strCreator = strCreator;
	}

	public String getDtCreatDate() {
		return dtCreatDate;
	}

	public void setDtCreatDate(String dtCreatDate) {
		this.dtCreatDate = dtCreatDate;
	}
    
    
    
    
    
	
    
   

    

    
}
